package com.itboye.ihomebank.me;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.InputFilter;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.ZuJinAdapter;
import com.itboye.ihomebank.adapter.fangyuan.ChaoXiangAdapter;
import com.itboye.ihomebank.adapter.fangyuan.ChengDuAdapter;
import com.itboye.ihomebank.adapter.fangyuan.ChuZuFangShiAdapter;
import com.itboye.ihomebank.adapter.fangyuan.ZhiFuFangShiAdapter;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.base.MyApplcation;
import com.itboye.ihomebank.bean.EditBean;
import com.itboye.ihomebank.bean.FaBuHouseBean;
import com.itboye.ihomebank.bean.HouseZiDianBean;
import com.itboye.ihomebank.bean.EditBean.HouseProps;
import com.itboye.ihomebank.bean.HouseZiDianBean.houseDecoration;
import com.itboye.ihomebank.bean.HouseZiDianBean.houseDevice;
import com.itboye.ihomebank.bean.HouseZiDianBean.houseFeature;
import com.itboye.ihomebank.bean.HouseZiDianBean.houseOrientation;
import com.itboye.ihomebank.bean.HouseZiDianBean.housePay;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.FlowLayout;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.presenter.UserPresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.CashierInputFilter;
import com.itboye.ihomebank.util.HuXingPopupWindow;
import com.itboye.ihomebank.util.SPUtils;
import com.itboye.ihomebank.util.WriteYongJinWindow;
import com.itboye.ihomebank.web.UploadImage.OnUploadlistener;
import com.itboye.ihomebank.wheelview.OnWheelScrollListener;
import com.itboye.ihomebank.wheelview.WheelView;
import com.itboye.ihomebank.wheelview.adapter.NumericWheelAdapter;

/**
 * 发布房源（2）
 * 
 */
public class ActivityFaBuHouseTwo extends BaseOtherActivity implements
		Observer, OnUploadlistener {
	private ImageView close_icon;// 返回图片
	private TextView add_shap_title_tv;// 标题

	private TextView fabu_house_ok;
	RelativeLayout fabu_two_zujin, fabu_two_dingjin, fabu_two_yongjin,
			fabu_two_mianji, fabu_two_huxing, fabu_two_zulin, fabu_two_louceng,
			fabu_two_chaoxiang, fabu_two_zong, fabu_two_chengdu,
			fabu_two_fangshi, fabu_two_miaoshu;
	// 户型
	private TextView fabu_huxing;
	ToggleButton fabu_yongjin;
	// 租金，佣金，面积，楼层，总楼层，描述
	private EditText fabu_zujin, fabu_mianji, fabu_louceng, fabu_zong,
			fabu_miaoshu;
	/** 装修程度，支付方式，朝向，租赁房间 */
	TextView fabu_chengdu, fabu_fangshi, fabu_chaoxiang, fabu_woshi;
	/** 详细地址 */
	 String addressdetail;
	EditText fabu_addressdetail;
	/** 装修程度的id，支付方式的id，朝向的id */
	private String chengdu, fangshi, chaoxiang;

	// 房源特色，室内配置
	FlowLayout fabu_flowLayout01, fabu_flowLayout02;
	// 房源特色
	private StringBuffer biao01 = new StringBuffer();
	// 室内配置
	private StringBuffer biao02 = new StringBuffer();

	PopupWindow mPopWin;

	/** 户型弹出框 */
	private HuXingPopupWindow huxingWindow;
	// 户型
	private WheelView huxing_01, huxing_02, huxing_03;
	Intent intent;
	String xiaoquCode, phone, people, title;
	private UserPresenter userPresenter;

	private HousePresenter housePresenter;// 用来获取房源字典

	private List<houseDecoration> house_decoration = new ArrayList<houseDecoration>();// 装修程度
	private List<housePay> house_pay = new ArrayList<housePay>();// 支付方式
	private List<houseFeature> house_feature = new ArrayList<HouseZiDianBean.houseFeature>();// 房源特色标签
	private List<houseDevice> house_device = new ArrayList<houseDevice>();// 室内配置
	private List<houseOrientation> house_orientation = new ArrayList<houseOrientation>();// 朝向

	private RelativeLayout layout;
	/** 装修程度 */
	ChengDuAdapter chengDuAdapter;
	/** 支付方式 */
	ZhiFuFangShiAdapter zhiFuFangShiAdapter;
	/** 房间朝向 */
	ChaoXiangAdapter ChaoXiangAdapter;
	/** 出租方式 */
	ChuZuFangShiAdapter chuZuFangShiAdapter;

	LinearLayout fabu_main;

	List<String> listPicture = new ArrayList<String>();

	List<String> listPic = new ArrayList<String>();

	/** 存图片的ID */
	private StringBuffer sb;

	List<String> data;
	/** 出租方式 : 【1=>整租,2=>合租-主卧,3=>合租-次卧】 */
	private int type;
	/** 户型，【1,0,0】 几室,几厅,几卫 */
	private String huxing;
	ArrayList<TextView> arrayListTeSe = new ArrayList<>();
	ArrayList<TextView> arrayListPeiZhi = new ArrayList<>();
	private StringBuffer stringTeSe=new StringBuffer();
	private StringBuffer stringPeiZhi=new StringBuffer();
	String detail;
	private String house_no = "";
	EditText edit_money;
	protected String yongjin;
	TextView yongjinwrite;
	EditBean editBean;
	private OnClickListener yongjinTianXieClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.yes:
				if (edit_money.getText().toString().equals("")) {
					ByAlert.alert("请先写佣金");
				} else {
					yongjin = edit_money.getText().toString();
					yongjinwrite.setText(yongjin + "元");
					jinWindow.dismiss();
				}

				break;
			case R.id.cancel:
				jinWindow.dismiss();
				break;
			default:
				break;
			}
			
		}
	};
	private WriteYongJinWindow jinWindow;
	private boolean isWeiTuo;

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;
		case R.id.fabu_yongjin:
			isWeiTuo = !isWeiTuo;
			if (isWeiTuo) {
				jinWindow = new WriteYongJinWindow(this,
						yongjinTianXieClickListener);
				edit_money = (EditText) jinWindow.getContentView()
						.findViewById(R.id.edit_money);
				jinWindow.showAtLocation(v, Gravity.BOTTOM
						| Gravity.CENTER_HORIZONTAL, 0, 0);
			} else {
				yongjin = "0";
				yongjinwrite.setText("");
			}
			break;
		case R.id.fabu_two_huxing:// 户型
			huxingWindow.showAtLocation(v, Gravity.BOTTOM
					| Gravity.CENTER_HORIZONTAL, 0, 0);
			break;
		case R.id.fabu_two_zulin:// 租赁房间
			chuzuPopWindow(v);
			break;
		case R.id.fabu_two_louceng:// 楼层

			break;
		case R.id.fabu_two_chaoxiang:// 楼层朝向
			ChaoXiangPopWindow(v);
			break;
		case R.id.fabu_two_chengdu:// 装修程度
			ChengDuPopWindow(v);
			break;
		case R.id.fabu_two_fangshi:// 支付方式
			ZhiFuPopWindow(v);
			break;
		case R.id.fabu_house_ok:// 完成
			String uid = (String) SPUtils.get(this, null, SPContants.USER_ID,
					"");
			String zujin = fabu_zujin.getText().toString();
			String mianji = fabu_mianji.getText().toString();
			String louceng = fabu_louceng.getText().toString();
			String zonglouceng = fabu_zong.getText().toString();
			String str = getIntent().getStringExtra("imgIds");
			addressdetail=getIntent().getStringExtra("address");
			if (str.toString().length() > 0) {
				str = str.toString().substring(0, str.length() - 1);
			}
			// addressdetail = fabu_addressdetail.getText().toString();
			if (zujin.equals("")) {
				ByAlert.alert("请填写租金");
				return;
			}
			if (type == 0) {
				ByAlert.alert("请选择出租方式");
				return;
			}
			if (mianji.equals("")) {
				ByAlert.alert("请选择面积");
				return;
			}
			if (louceng.equals("")) {
				ByAlert.alert("请填写楼层");
				return;
			}
			if (zonglouceng.equals("")) {
				ByAlert.alert("请选择总楼层");
				return;
			}
			if (chaoxiang == null) {
				ByAlert.alert("请选择朝向");
				return;
			}
			if (chengdu == null) {
				ByAlert.alert("请选择装修程度");
				return;
			}
			if (fangshi == null) {
				ByAlert.alert("请选择支付方式");
				return;
			}
			if (huxing == null) {
				ByAlert.alert("请选择户型");
				return;
			}
			if (isWeiTuo) {
				if (yongjin == null) {
					ByAlert.alert("请填写佣金");
					return;
				}
			}
			// if (addressdetail == null) {
			// ByAlert.alert("请填写详细地址");
			// return;
			// }
			stringTeSe = new StringBuffer();
			for (int i = 0; i < arrayListTeSe.size(); i++) {
				if (arrayListTeSe.get(i).getTag(R.id.tagNames).toString()
						.equals("select")) {
					stringTeSe.append(arrayListTeSe.get(i).getTag(R.id.tag)
							.toString()
							+ ",");
				}
			}
			stringPeiZhi = new StringBuffer();
			for (int i = 0; i < arrayListPeiZhi.size(); i++) {
				if (arrayListPeiZhi.get(i).getTag(R.id.tagNames).toString()
						.equals("select")) {
					stringPeiZhi.append(arrayListPeiZhi.get(i).getTag(R.id.tag)
							.toString()
							+ ",");
				}
			}
			showProgressDialog("正在发布中,请稍后", false);
			// userPresenter.getHouseAdd("11",str, "330110d602", 1, "张三",
			// "15238515554", 2000, 50, "6,6,6", 5, 20, "6201", "6225,6230",
			// "6194",
			// "杭州滨江");学院路159号附近
			userPresenter.getHouseAdd(
					uid,
					str == null ? "" : str,
					xiaoquCode,
					type,
					people,
					phone,
					isWeiTuo ? Double.parseDouble(zujin) * 100 + "" : "0",
					mianji,
					huxing,
					louceng,
					zonglouceng,
					chengdu,
					fangshi,
					chaoxiang,
					addressdetail,
					Double.parseDouble(yongjin) *100 + "",
					stringTeSe.toString().length() > 0 ? stringTeSe.substring(
							0, stringTeSe.length() - 1) : "",
					stringPeiZhi.toString().length() > 0 ? stringPeiZhi
							.substring(0, stringPeiZhi.length() - 1) : "", "",
					house_no == null ? "" : house_no, "");
			break;

		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		return R.layout.activity_fabu_house_two;
	}

	@Override
	protected void onInit() {
		editBean = (EditBean) getIntent().getSerializableExtra("model");// 是否是修改房源，editbean为空即发布房源，不为空即为修改房源
		if (editBean != null) {
			fabu_zujin
					.setText((Double.parseDouble(editBean.getRent() + "") / 100 + ""));
			fabu_fangshi.setText(editBean.getPayTypes().get(0).getName());
			fangshi=editBean.getPayTypes().get(0).getId()+"";
			fabu_mianji.setText(editBean.getHouseArea()+"");
			fabu_huxing.setText(editBean.getHouseRoom() + "室"
					+ editBean.getHouseHall() + "厅" + editBean.getToilet()
					+ "卫");
			fabu_woshi.setText(editBean.getRentTypeName()+"");
			type=editBean.getRentType();
			fabu_louceng.setText(editBean.getFloorAt()+"");

			fabu_zong.setText(editBean.getFloorAll()+"");
			fabu_chaoxiang.setText(editBean.getHouseDirName());
			fabu_chengdu.setText(editBean.getHouseDecorationName());
			// fabu_flowLayout01//房源特色
//			if (editBean.getTags() != null && editBean.getTags().size() > 0) {
//				for (int i = 0; i < editBean.getTags().size(); i++) {
//
//				}
//			}
//			if (editBean.getHouseProps().size() > 0
//					&& editBean.getHouseProps() != null) {
//				for (int i = 0; i < editBean.getHouseProps().size(); i++) {
//
//				}
//			}

			// fabu_flowLayout02//室内配置
			fabu_miaoshu.setText(editBean.get_abstract());
			if (editBean.getEntrustMoney()<=0) {
				isWeiTuo = false;
				yongjinwrite.setText("");
				fabu_yongjin.setChecked(false);
			} else {
				isWeiTuo = true;
				yongjinwrite.setText(Double.parseDouble(editBean
						.getEntrustMoney() + "")
						/ 100 + "元");
				fabu_yongjin.setChecked(true);
			}
		} else {

		}
		add_shap_title_tv.setText("发布房源");
		huXingPop();
		sb = new StringBuffer();
		intent = this.getIntent();
		userPresenter = new UserPresenter(this);
		xiaoquCode = intent.getStringExtra("xiaoquCode");
		house_no = intent.getStringExtra("house_no");
		phone = intent.getStringExtra("phone");
		people = intent.getStringExtra("people");
		title = intent.getStringExtra("title");

		detail = intent.getStringExtra("detail");
		housePresenter = new HousePresenter(this);
		housePresenter.houseZiDian("");

		InputFilter[] filter = { new CashierInputFilter() };
		fabu_zujin.setFilters(filter);// 设置输入位金额
		// fabu_yongjin.setFilters(filter);// 设置输入位金额

	}

	@Override
	protected void onInitController() {

	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity entity = handlerError(data);
		// ByAlert.alert(entity.getData());

		if (entity != null) {
			if (!entity.getCode().equals(0)) {
				if (entity.getEventType() == UserPresenter.user_success) {
					FaBuHouseBean bean = (FaBuHouseBean) entity.getData();
				} else if (entity.getEventType() == UserPresenter.user_fail) {

				}
				// 房源字典
				if (entity.getEventType() == HousePresenter.houseZiDian_success) {

					HouseZiDianBean houseZiDianBean = (HouseZiDianBean) entity
							.getData();

					if (houseZiDianBean != null) {
						house_decoration.addAll(houseZiDianBean
								.getHouse_decoration());

						house_pay.addAll(houseZiDianBean.getHouse_pay());
						house_feature
								.addAll(houseZiDianBean.getHouse_feature());
						house_device.addAll(houseZiDianBean.getHouse_device());
						house_orientation.addAll(houseZiDianBean
								.getHouse_orientation());

						HouseTeSe();
						peiZhi();
					}

					Log.i("Result", entity.getData().toString());

				} else if (entity.getEventType() == HousePresenter.houseZiDian_fail) {

				} else if (entity.getEventType() == UserPresenter.houseAdd_success) {
					ByAlert.alert(entity.getData());
					ActivityFaBuHouse.getInstance().guanbi();// 关闭第一个页面
					finish();
				} else if (entity.getEventType() == UserPresenter.houseAdd_fail) {
					ByAlert.alert(entity.getData());
				}
			}
		}
		try {
			closeProgressDialog();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	/**
	 * 户型
	 */
	OnClickListener huxingListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.huxing_cancel:
				huxingWindow.dismiss();
				break;
			case R.id.huxing_ok:// 完成
				huxingWindow.dismiss();
				fabu_huxing.setText(huxing_01.getCurrentItem() + 1 + "室"
						+ (huxing_02.getCurrentItem() + 0) + "厅"
						+ (huxing_03.getCurrentItem() + 1) + "卫");

				huxing = (huxing_01.getCurrentItem() + 1) + ","
						+ (huxing_02.getCurrentItem() + 0) + ","
						+ (huxing_03.getCurrentItem() + 1) + "";

				break;

			default:
				break;
			}

		}

	};

	/**
	 * 弹出框
	 */
	private void huXingPop() {
		// 户型
		huxingWindow = new HuXingPopupWindow(this, huxingListener);
		huxing_01 = (WheelView) huxingWindow.getContentView().findViewById(
				R.id.huxing_01);
		huxing_01.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume02 = new NumericWheelAdapter(MyApplcation.ctx,
				1, 4);
		nume02.setLabel("室");
		huxing_01.setViewAdapter(nume02);
		huxing_01.setCyclic(true);// 是否可循环滑动
		huxing_01.addScrollingListener(scrollListener);

		huxing_02 = (WheelView) huxingWindow.getContentView().findViewById(
				R.id.huxing_02);
		huxing_02.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume03 = new NumericWheelAdapter(MyApplcation.ctx,
				0, 3);
		nume03.setLabel("厅");
		huxing_02.setViewAdapter(nume03);
		huxing_02.setCyclic(true);// 是否可循环滑动
		huxing_02.addScrollingListener(scrollListener);

		huxing_03 = (WheelView) huxingWindow.getContentView().findViewById(
				R.id.huxing_03);
		huxing_03.setBackgroundResource(R.drawable.white);
		NumericWheelAdapter nume04 = new NumericWheelAdapter(MyApplcation.ctx,
				1, 2);
		nume04.setLabel("卫");
		huxing_03.setViewAdapter(nume04);
		huxing_03.setCyclic(true);// 是否可循环滑动
		huxing_03.addScrollingListener(scrollListener);
	}

	OnWheelScrollListener scrollListener = new OnWheelScrollListener() {
		@Override
		public void onScrollingStarted(WheelView wheel) {

		}

		@Override
		public void onScrollingFinished(WheelView wheel) {
		}
	};
	private ArrayList<TextView> listText=new ArrayList<>();
	private ArrayList<TextView> listTextViewPeiZhi=new ArrayList<>();

	/**
	 * 房源特色
	 */
	@SuppressLint("NewApi")
	private void HouseTeSe() {
		StringBuffer tagIds = new StringBuffer();
		if (house_feature.size() > 0) {
			for (int i = 0; i < house_feature.size(); i++) {
				biao01.append(house_feature.get(i).getName() + ",");
				tagIds.append(house_feature.get(i).getId() + ",");
			}
			String[] str = biao01.toString().split(",");
			String[] ids = tagIds.toString().split(",");
			// 标签
			for (int i = 0; i < str.length; i++) {
				View view = LayoutInflater.from(this).inflate(
						R.layout.item_jiaju, null);
				final TextView btn_name = (TextView) view
						.findViewById(R.id.btn_name);
				
				listText.add(btn_name);
				btn_name.setBackgroundResource(R.drawable.shape_gray);
				btn_name.setText(str[i]);
				btn_name.setTag(false);
				btn_name.setTag(R.id.tagNames, "unSelect");
				btn_name.setTag(R.id.tag, ids[i]);
				arrayListTeSe.add(btn_name);
				btn_name.setTextColor(Color.parseColor("#5B5B5B"));
				btn_name.setOnClickListener(new OnClickListener() {

					@SuppressLint("ResourceAsColor")
					public void onClick(View v) {
						if (!(boolean) v.getTag()) {
							btn_name.setBackgroundResource(R.drawable.shape_blue02);
							btn_name.setTextColor(Color.parseColor("#B1CCFC"));
							btn_name.setTag(R.id.tagNames, "select");
						} else {
							btn_name.setBackgroundResource(R.drawable.shape_gray);
							btn_name.setTextColor(Color.parseColor("#5B5B5B"));
							btn_name.setTag(R.id.tagNames, "unSelect");
						}
						v.setTag(!(boolean) v.getTag());
					}
				});
				MarginLayoutParams layoutParams = new MarginLayoutParams(
						MarginLayoutParams.WRAP_CONTENT,
						MarginLayoutParams.WRAP_CONTENT);
				layoutParams.setMargins(10, 10, 10, 10);
				fabu_flowLayout01.addView(view, layoutParams);
			}
			if(editBean!=null){
			for (int i = 0; i < str.length; i++) {
				for (int j = 0; j < editBean.getTags().size(); j++) {
					if(str[i].equals(editBean.getTags().get(j).getName())){
						stringTeSe.append(editBean.getTags().get(j).getId()+",");
						listText.get(i).setTag(true);
						listText.get(i).setBackgroundResource(R.drawable.shape_blue02);
						listText.get(i).setTextColor(Color.parseColor("#B1CCFC"));
						listText.get(i).setTag(R.id.tagNames, "select");
					}
				}
			}
			}
			
		}
	}

	/**
	 * 室内配置
	 */
	@SuppressLint("NewApi")
	private void peiZhi() {
		StringBuffer bufferIds = new StringBuffer();
		if (house_device.size() > 0) {
			for (int i = 0; i < house_feature.size(); i++) {
				biao02.append(house_device.get(i).getName() + ",");
				bufferIds.append(house_device.get(i).getId() + ",");
			}
			String[] str = biao02.toString().split(",");
			String[] ids = bufferIds.toString().split(",");
			for (int i = 0; i < str.length; i++) {
				View view = LayoutInflater.from(this).inflate(
						R.layout.item_jiaju, null);
				final TextView btn_name = (TextView) view
						.findViewById(R.id.btn_name);
				listTextViewPeiZhi.add(btn_name);
				btn_name.setBackgroundResource(R.drawable.shape_gray);
				btn_name.setText(str[i]);
				btn_name.setTag(false);
				btn_name.setTag(R.id.tagNames, "unSelect");
				btn_name.setTag(R.id.tag, ids[i]);
				arrayListPeiZhi.add(btn_name);
				btn_name.setTextColor(Color.parseColor("#5B5B5B"));
				btn_name.setOnClickListener(new OnClickListener() {

					@SuppressLint({ "ResourceAsColor", "NewApi" })
					public void onClick(View v) {
						if (!(boolean) v.getTag()) {
							btn_name.setBackgroundResource(R.drawable.shape_blue02);
							btn_name.setTextColor(Color.parseColor("#B1CCFC"));
							btn_name.setTag(R.id.tagNames, "select");
						} else {
							btn_name.setBackgroundResource(R.drawable.shape_gray);
							btn_name.setTextColor(Color.parseColor("#5B5B5B"));
							btn_name.setTag(R.id.tagNames, "unSelect");
						}
						v.setTag(!(boolean) v.getTag());
					}
				});

				MarginLayoutParams layoutParams = new MarginLayoutParams(
						MarginLayoutParams.WRAP_CONTENT,
						MarginLayoutParams.WRAP_CONTENT);
				layoutParams.setMargins(10, 10, 10, 10);
				fabu_flowLayout02.addView(view, layoutParams);
			}
			if(editBean!=null){
			for (int i = 0; i < str.length; i++) {
				for (int j = 0; j < editBean.getHouseProps().size(); j++) {
					if(str[i].equals(editBean.getHouseProps().get(j).getName())){
						stringPeiZhi.append(editBean.getHouseProps().get(j).getId()+",");
						listTextViewPeiZhi.get(i).setTag(true);
						listTextViewPeiZhi.get(i).setBackgroundResource(R.drawable.shape_blue02);
						listTextViewPeiZhi.get(i).setTextColor(Color.parseColor("#B1CCFC"));
						listTextViewPeiZhi.get(i).setTag(R.id.tagNames, "select");
					}
				}
			}
			}
		}
	}

	/**
	 * 裝修程度
	 */
	private void ChengDuPopWindow(View v) {
		layout = (RelativeLayout) LayoutInflater
				.from(ActivityFaBuHouseTwo.this).inflate(
						R.layout.popup_fangyuan, null);

		ListView fangyuan_listView = (ListView) layout
				.findViewById(R.id.fangyuan_listView);

		if (house_decoration != null) {
			if (house_decoration.size() > 0) {

				chengDuAdapter = new ChengDuAdapter(this, house_decoration);

				fangyuan_listView.setAdapter(chengDuAdapter);

				mPopWin = new PopupWindow(layout,
						ViewGroup.LayoutParams.MATCH_PARENT,
						ViewGroup.LayoutParams.MATCH_PARENT, true);
				mPopWin.setBackgroundDrawable(new BitmapDrawable());
				mPopWin.showAsDropDown(fabu_two_zujin, 0, 0);
				mPopWin.update();

				fangyuan_listView
						.setOnItemClickListener(new OnItemClickListener() {

							@Override
							public void onItemClick(AdapterView<?> parent,
									View view, int position, long id) {
								chengdu = house_decoration.get(position)
										.getId();
								fabu_chengdu.setText(house_decoration.get(
										position).getName());
								mPopWin.dismiss();
							}
						});
			}
		}
	}

	/**
	 * 支付方式
	 */
	private void ZhiFuPopWindow(View v) {
		layout = (RelativeLayout) LayoutInflater
				.from(ActivityFaBuHouseTwo.this).inflate(
						R.layout.popup_fangyuan, null);

		ListView fangyuan_listView = (ListView) layout
				.findViewById(R.id.fangyuan_listView);

		if (house_pay != null) {
			if (house_pay.size() > 0) {

				zhiFuFangShiAdapter = new ZhiFuFangShiAdapter(this, house_pay);

				fangyuan_listView.setAdapter(zhiFuFangShiAdapter);

				mPopWin = new PopupWindow(layout,
						ViewGroup.LayoutParams.MATCH_PARENT,
						ViewGroup.LayoutParams.MATCH_PARENT, true);
				mPopWin.setBackgroundDrawable(new BitmapDrawable());
				mPopWin.showAsDropDown(fabu_two_zujin, 0, 0);
				mPopWin.update();

				fangyuan_listView
						.setOnItemClickListener(new OnItemClickListener() {

							@Override
							public void onItemClick(AdapterView<?> parent,
									View view, int position, long id) {
								fangshi = house_pay.get(position).getId();
								fabu_fangshi.setText(house_pay.get(position)
										.getName());
								mPopWin.dismiss();
							}
						});
			}
		}
	}

	/**
	 * 房源朝向
	 */
	private void ChaoXiangPopWindow(View v) {
		layout = (RelativeLayout) LayoutInflater
				.from(ActivityFaBuHouseTwo.this).inflate(
						R.layout.popup_fangyuan, null);

		ListView fangyuan_listView = (ListView) layout
				.findViewById(R.id.fangyuan_listView);

		if (house_orientation != null) {
			if (house_orientation.size() > 0) {

				ChaoXiangAdapter = new ChaoXiangAdapter(this, house_orientation);

				fangyuan_listView.setAdapter(ChaoXiangAdapter);

				mPopWin = new PopupWindow(layout,
						ViewGroup.LayoutParams.MATCH_PARENT,
						ViewGroup.LayoutParams.MATCH_PARENT, true);
				mPopWin.setBackgroundDrawable(new BitmapDrawable());
				mPopWin.showAsDropDown(fabu_two_zujin, 0, 0);
				mPopWin.update();

				fangyuan_listView
						.setOnItemClickListener(new OnItemClickListener() {

							@Override
							public void onItemClick(AdapterView<?> parent,
									View view, int position, long id) {
								chaoxiang = house_orientation.get(position)
										.getId();
								fabu_chaoxiang.setText(house_orientation.get(
										position).getName());
								mPopWin.dismiss();
							}
						});
			}
		}
	}

	/**
	 * 出租方式
	 */
	private void chuzuPopWindow(View v) {
		layout = (RelativeLayout) LayoutInflater
				.from(ActivityFaBuHouseTwo.this).inflate(
						R.layout.popup_fangyuan, null);

		ListView fangyuan_listView = (ListView) layout
				.findViewById(R.id.fangyuan_listView);
		chuZuFangShiAdapter = new ChuZuFangShiAdapter(this, getData());
		fangyuan_listView.setAdapter(chuZuFangShiAdapter);

		mPopWin = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT,
				ViewGroup.LayoutParams.MATCH_PARENT, true);
		mPopWin.setBackgroundDrawable(new BitmapDrawable());
		mPopWin.showAsDropDown(fabu_two_zujin, 0, 0);
		mPopWin.update();

		fangyuan_listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				fabu_woshi.setText(data.get(position).toString());
				type = position + 1;
				mPopWin.dismiss();

			}
		});

	}

	/**
	 * 出租方式的数据
	 */
	private List<String> getData() {
		data = new ArrayList<String>();
		data.add("整租");
		data.add("合租-主卧");
		data.add("合租-次卧");
		return data;
	}

	@Override
	public void OnSuccess(String resultData) {
		sb.append(resultData + ",");
		ByAlert.alert(resultData);
	}

	@Override
	public void OnError(String resultData) {
		ByAlert.alert(resultData);

	}
}
